from bs4 import BeautifulSoup

def bsAPage(text,commentList):
    soup = BeautifulSoup(text, "html.parser")
    commentsTag = soup.find('div', id='comments')
    for commentItemTag in commentsTag.find_all('li', class_='comment-item'):
        commentInfoTag = commentItemTag.find('span', class_='comment-info')
        # 评论作者
        author = commentInfoTag.find('a').string
        # 推荐星星数
        # userstar= commentInfoTag.find('span')
        userstar = commentInfoTag.find('span')['title']
        # 评论时间
        time = commentInfoTag.find('a', class_='comment-time').string
        # 评论内容
        content = commentItemTag.find('p', class_='comment-content').find('span').string
        # 赞同该评论的人数
        votecount = commentItemTag.find('span', class_='vote-count').string
        # 加入到评论列表comments中
        commentList.append([author, userstar, time, content, votecount])

if __name__ == '__main__':
    commentList = []
    for i in range(2):
        file=open("评论第"+str(i)+"页.txt",'rb')
        text = file.read()
        bsAPage(text,commentList)
        file.close()

for item in commentList:
    print(item)